package cn.ylyhappy.netdemo.config

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class RetryInterceptor (private  val maxRetry: Int = 0) : Interceptor{
    companion object {
        private const val TAG = "RetryInterceptor"
    }
    private var retryNum: Int = 0
    override fun intercept(chain: Interceptor.Chain): Response {
        val request: Request = chain.request()
        Log.d(TAG, "intercept 29line, current retryNum=${retryNum} ")
        var response = chain.proceed(request)
        while (response.isSuccessful && retryNum < maxRetry){
            retryNum++
            Log.d(TAG, "intercept: 33line, current retryNum=$retryNum")
            response = chain.proceed(request)
        }
        return response
    }
}